package com.das.mechanic_base.adapter.main;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.alone.DashboardWarnBean;
import com.das.mechanic_base.utils.X3StringUtils;

import java.util.ArrayList;
import java.util.List;

public class X3AppearanceRecognitionStausAdapter extends RecyclerView.Adapter<X3AppearanceRecognitionStausAdapter.RecognitionStatusHolder> {

    private Context mContext;

    private List<DashboardWarnBean.RecognitionResult> mList;
    public X3AppearanceRecognitionStausAdapter(Context mContext) {
        this.mContext = mContext;
        this.mList = new ArrayList<>();
    }

    public void setList(List<DashboardWarnBean.RecognitionResult> mList) {
        this.mList.clear();
        this.mList.addAll(mList);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public X3AppearanceRecognitionStausAdapter.RecognitionStatusHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new RecognitionStatusHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_main_appearance_recognition_status_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull X3AppearanceRecognitionStausAdapter.RecognitionStatusHolder holder, int position) {
            if(mList.size() == 1 || mList.size() == 2 || mList.size() == 3 || mList.size() == 4 || mList.size() == 5 || mList.size() == 6 || mList.size() == 7 || mList.size() == 8 ||  mList.size() == 9 ){

                int newPosition = position + 1;
                holder.tv_name_sequence.setText("0"+newPosition);

            }else if(mList.size() >= 10){

                if(position < 9){

                    int newPosition = position + 1;
                    holder.tv_name_sequence.setText("0"+newPosition);

                }else {

                    int newPosition = position + 1;
                    holder.tv_name_sequence.setText(newPosition+"");

                }

            }
            holder.tv_name.setText(mList.get(position).parts);
            holder.tv_damage_value.setText(mList.get(position).type);
            if(mList.get(position).ifManEdit){//是否是人工判断
                holder.rl_area_ratio.setVisibility(View.GONE);
                holder.rl_damage_area.setVisibility(View.GONE);
                holder.tv_scorce_value.setText(mList.get(position).probability+"%"+"("+mContext.getString(R.string.x3_huma_recognition)+")");
            }else {
                holder.rl_area_ratio.setVisibility(View.VISIBLE);
                holder.rl_damage_area.setVisibility(View.VISIBLE);
                holder.tv_scorce_value.setText(mList.get(position).probability+"%");
            }

            double doubleum = X3StringUtils.doubleum(mList.get(position).totalArea, 1);
            holder.tv_damage_area_value.setText(doubleum+"c㎡");
            double totalRatio = mList.get(position).totalRatio;
            double totalRatios =  totalRatio*100;
            double totalRationew = X3StringUtils.doubleum(totalRatios, 1);
            holder.tv_area_ratio_value.setText(totalRationew+"%");
    }



    @Override
    public int getItemCount() {
        return mList.size();
    }

    class RecognitionStatusHolder extends RecyclerView.ViewHolder {
        TextView tv_name;
        TextView tv_name_sequence;
        TextView tv_damage;
        TextView tv_damage_value;
        TextView tv_scorce;
        TextView tv_scorce_value;
        TextView tv_damage_area;
        TextView tv_damage_area_value;
        TextView tv_area_ratio;
        TextView tv_area_ratio_value;
        RelativeLayout rl_damage_area;
        RelativeLayout rl_area_ratio;
        public RecognitionStatusHolder(@NonNull View itemView) {
            super(itemView);
            tv_name=itemView.findViewById(R.id.tv_name);
            tv_name_sequence=itemView.findViewById(R.id.tv_name_sequence);
            tv_damage=itemView.findViewById(R.id.tv_damage);
            tv_damage_value=itemView.findViewById(R.id.tv_damage_value);
            tv_scorce=itemView.findViewById(R.id.tv_scorce);
            tv_scorce_value=itemView.findViewById(R.id.tv_scorce_value);
            tv_damage_area=itemView.findViewById(R.id.tv_damage_area);
            tv_damage_area_value=itemView.findViewById(R.id.tv_damage_area_value);
            tv_area_ratio=itemView.findViewById(R.id.tv_area_ratio);
            tv_area_ratio_value=itemView.findViewById(R.id.tv_area_ratio_value);
            rl_damage_area=itemView.findViewById(R.id.rl_damage_area);
            rl_area_ratio=itemView.findViewById(R.id.rl_area_ratio);
        }
    }
}
